package com.guigu.service_user.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.service_user.entity.TbAreas;
import com.guigu.service_user.entity.TbCities;
import com.guigu.service_user.service.ITbAreasService;
import com.guigu.service_user.service.ITbCitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 行政区域地州市信息表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-07-09
 */
@RestController
@RequestMapping("/service_user/tb-cities")
public class TbCitiesController {
    @Autowired
    private ITbCitiesService citiesService;

    // 分页条件查询
    @PostMapping("/findPage")
    public Result findPage(@RequestBody(required = false) Map<String, Object> searchMap, Integer page, Integer size) {
        return citiesService.findPage(searchMap, page, size);
    }
    //增加
    @PostMapping("/insert")
    public Result insert(@RequestBody TbCities album) {
        boolean save = citiesService.save(album);
        if (save){
            return Result.ok();
        }
        return Result.error();
    }
    //修改
    @PostMapping("/update")
    public Result update(@RequestBody TbCities album) {
        boolean update = citiesService.updateById(album);
        if (update) {
            return Result.ok();
        }
        return Result.error();
    }
    //删除
    @GetMapping("/delete")
    public Result delete(Integer id) {
        boolean remove = citiesService.removeById(id);
        if (remove){
            return Result.ok();
        }
        return Result.error();
    }
    //查询单个
    @GetMapping("/findById")
    public Result findById(Integer id) {
        TbCities album = citiesService.getById(id);
        if (album==null){
            return Result.error();
        }
        return Result.ok().data("cities",album);
    }
}

